import { types } from "mobx-state-tree"

export const GlobalStoreModel = types
  .model("GlobalStoreModel", {
    isLogin: false,
    isLoginXJ: false,
    showModalVisible: false,
    logoutModalVisible: false,
    userInfo: types.frozen()
  })
  .actions(self => ({
    loginSuccess(userInfo) {
      self.isLogin = true
      self.userInfo = userInfo
    },

    showLogoutModal() {
      self.logoutModalVisible = true
    },

    closeModal() {
      self.showModalVisible = false
    },

    closeLogoutModal() {
      self.logoutModalVisible = false
    },

    confirmLogout() {
      self.isLogin = false
      self.logoutModalVisible = false
    },

    checkLogin(navigation: any, router: string, params: any) {
      if (!self.isLogin) {
        self.showModalVisible = true
      } else {
        navigation.navigate(router, params || {})
      }
    }
  }))
